#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ls (x << 1)
#define rs (x << 1 | 1)
using namespace std;

const ll N = 2e5 + 10, P = 998244353;

ll n, m;
struct node
{
    ll l, r, sum, lazy;
    ll len() { return r - l + 1; }
}tr[N << 2];
ll inv[N];

void pushup(ll x) { tr[x].sum = (tr[ls].sum + tr[rs].sum) % P; }
void pushdown(ll x) {
    if (tr[x].lazy != -1) {
        tr[ls].lazy = tr[rs].lazy = tr[x].lazy;

        tr[ls].sum = tr[x].lazy * tr[ls].len() % P;
        tr[rs].sum = tr[x].lazy * tr[rs].len() % P;

        tr[x].lazy = -1;
    }
}

void build(ll x, ll l, ll r)
{
    tr[x].l = l, tr[x].r = r;
    tr[x].lazy = -1;
    if (l == r) { cin >> tr[x].sum; return; }
    ll mid = (l + r) >> 1;
    build(ls, l, mid);build(rs, mid + 1, r);
    pushup(x);
}

void modify(ll x, ll l, ll r, ll v)
{
    if (l <= tr[x].l && tr[x].r <= r) {
        tr[x].sum = v * tr[x].len() % P;
        tr[x].lazy = v;
        return;
    }
    pushdown(x);
    ll mid = (tr[x].l + tr[x].r) >> 1;
    if (l <= mid) modify(ls, l, r, v);
    if (r > mid) modify(rs, l, r, v);
    pushup(x);
}

ll query(ll x, ll l, ll r)
{
    if (l <= tr[x].l && tr[x].r <= r) return tr[x].sum;
    pushdown(x);
    ll mid = (tr[x].l + tr[x].r) >> 1, res = 0;
    if (l <= mid) (res += query(ls, l, r)) %= P;
    if (r > mid) (res += query(rs, l, r)) %= P;
    return res;
}

void dfs(ll x)
{
    if (tr[x].l == tr[x].r) { cout << tr[x].sum << ' '; return; }
    pushdown(x);
    dfs(ls);dfs(rs);
}

void solve()
{
    inv[1] = 1;
    for (ll i = 2;i <= 2e5;i++) inv[i] = P - (P / i * inv[P % i] % P) % P;

    cin >> n >> m;
    build(1, 1, n);

    ll l, r;
    while (m--) {
        cin >> l >> r;
        ll v = query(1, l, r) * inv[r - l + 1] % P;
        modify(1, l, r, v);
    }

    dfs(1);
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}